<?php

namespace app\admin\model;

use think\Model;
use think\Db;

class Attr extends Model
{
    // 表名
    protected $name = 'attr';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = ['category_id_text'];

    public function getAttrData($category_id){
        $data = Db::name('attr')->where(['category_id' => $category_id])->select();

        return $data;
    }



    public function getCategoryIdTextAttr($value, $data)
    {
        $value = $value ? $value : $data['category_id'];
        $categoryM = new \app\common\model\Category();
        $list = $categoryM->getList('goods');
        return isset($list[$value]) ? $list[$value] : '';
    }

}
